package com.itheima.HomeWork_day07;

import java.util.Scanner;

public class ExceptionTest {
    public static void main(String[] args) {
        Student st=new Student();

        Scanner sc=new Scanner(System.in);
        System.out.println("请输入姓名:");
        String name=sc.next();
        st.setName(name);

        while(true){

            try {
                System.out.println("请输入年龄:");
                String strAge=sc.next();
                int age=Integer.parseInt(strAge);
                st.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数");
                continue;
            }catch (AgeOutOfBoundsException e1){
                System.out.println("年龄超出范围");
                continue;
            }
        }

        System.out.println(st.toString());
    }
}
